import { deepCopy } from '@/utils/tools'

enum syCode{
    'diSanZhe' = 10100,
    'siJi' = 10200,
    'chengKe' = 10300,
    'daoQiang' = 10400,
    'cheSun' = 10500,
    'huaHen' = 10501,
    'sheShui' = 10502,
    'boLi' = 10503,
    'ziRan' = 10504,
    'trdLosting' = 10505,
    'fixerAssigned' = 10506,
}

const labelConf = {

  diSanZhe:  '三者',
  siJi: '司机',
  chengKe: '乘客',
  daoQiang: '盗抢',
  cheSun: '车损',
  huaHen: '划痕',
  sheShui: '涉水',
  boLi: '玻璃',
  ziRan: '自燃',
  fixerAssigned: '专修',
  trdLosting: '无第三方',
  jqTotal: '交强小计',
  syTotal: '商业小计',
  mianPei: '不计免赔'
  
}


// 原模板(自定义)
const source:formInf.syData[] = [
    {
      "name":'三者',
      "checked": false,
      "key": "diSanZhe",
      "value": 50000,
      "jp": false
    },
    {
      "name": "司机",
      "checked": false,
      "key": "siJi",
      "value": 10000,
      "jp": false
    },
    {
      "name":"乘客", 
      "checked": false,
      "key": "chengKe",
      "value": 10000,
      "jp": false
    },
    {
      "name": "盗抢",
      "checked": false,
      "key": "daoQiang",
      "value": 0,
      "jp": false
    },
    {
      "name": "车损",
      "checked": false,
      "key": "cheSun",
      "value": 0,
      "jp": false
    },
    {
      "name": "划痕",
      "checked": false,
      "key": "huaHen",
      "value": 5000,
      "jp": false
    },
    {
      "name": "涉水",
      "checked": false,
      "key": "sheShui",
      "value": 0,
      "jp": false
    },
    {
      "name": "玻璃",
      "checked": false,
      "key": "boLi",
      "value": "国产",
      "jp": false
    },
    {
      "name": "自燃",
      "checked": false,
      "key": "ziRan",
      "value": 0,
      "jp": false
    },
    {
      "name": "第三方",
      "checked": false,
      "key": "trdLosting",
      "value": 0,
      "jp": false
    },
    {
      "name": "专修特约",
      "checked": false,
      "key": "fixerAssigned",
      "value": 0,
      "jp": false
    }
];

// 全保
const full:formInf.syData[] = createdPreConf(source, [
  {
    "checked": true,
    "key": "diSanZhe",
    "value": 500000,
    "jp": true
  },
  {
    "checked": true,
    "key": "siJi",
    "value": 10000,
    "jp": true
  },
  {
    "checked": true,
    "key": "chengKe",
    "value": 10000,
    "jp": true
  },
  {
    "checked": true,
    "key": "daoQiang",
    "value": 0,
    "jp": true
  },
  {
    "checked": true,
    "key": "cheSun",
    "value": 0,
    "jp": true
  },
  {
    "checked": true,
    "key": "boLi",
    "value": "国产",
    "jp": true
  },
  {
    "checked": true,
    "key": "trdLosting",
    "value": 0,
    "jp": false
  },

])

// 单三者
const onlyThree:formInf.syData[] = createdPreConf(source, [

  {
    "checked": true,
    "key": "diSanZhe",
    "value": 500000,
    "jp": true,
  },
  
])

// 单三者+座位
const threeAndSeat:formInf.syData[] = createdPreConf(source, [

  {
    "checked": true,
    "key": "diSanZhe",
    "value": 500000,
    "jp": true
  },
  {
    "checked": true,
    "key": "siJi",
    "value": 10000,
    "jp": true
  },
  {
    "checked": true,
    "key": "chengKe",
    "value": 10000,
    "jp": true
  },
  
])


// 预设配置
const preConf = {
    self:source,
    full,
    onlyThree,
    threeAndSeat
}

const preAPI = {
  full: "全保",
  onlyThree: "单三者",
  threeAndSeat: "单三者+座位",
  self: "自定义",
}

const keys = [
    'diSanZhe',
    'siJi',
    'chengKe',
    'daoQiang',
    'cheSun',
    'huaHen',
    'sheShui',
    'boLi',
    'ziRan',
    'trdLosting',
    'fixerAssigned',
]

enum EnumKeys{
    'diSanZhe',
    'siJi',
    'chengKe',
    'daoQiang',
    'cheSun',
    'huaHen',
    'sheShui',
    'boLi',
    'ziRan',
    'trdLosting',
    'fixerAssigned',
}

// 关键字列表
function keyList (isEnum:boolean=false){
  return isEnum ? EnumKeys : keys  
}

// 获取预设配置
function getPreConfItem (detailsClass, preConf){
    let keys = Object.keys(preAPI)

    for(let key of keys){
        
        if(preAPI[key] === detailsClass){
            return preConf[key];
        }
        
    }
}


// 预设列表名称
function preConfClass (){
    let keys = [];

    Object.keys(preAPI).forEach(key =>{
        keys.push(preAPI[key]);
    })
        
    return keys;
}

// 预设列表
function preConfList(){
  return deepCopy(preConf);
}

// 创建预设配置 template:构建模板 sign:标识标记  preConf:配置
function  createdPreConf (template,preConf:any[], sign:string='key',){
  template = deepCopy(template)

  template.forEach((templateItem, index) =>{

    preConf.forEach(confItem =>{

      if(templateItem[sign] === confItem[sign]){
        template[index] = Object.assign(templateItem, confItem)
      }
      
    })
    
  })

  return template;
  
}

  
// 还原
function reduction(syRisk:formInf.syData[]){


}


export {

    // 关键字
    keyList,
    
    // 代码映射
    syCode,

    // 还原
    reduction,
    
    // 预设配置列表
    preConfList,

    // 预设映射
    preAPI,

    // 获取对应配置
    getPreConfItem,

    // label关键字
    preConfClass,

    labelConf

}
